using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWASTLAGE
    {
        public DataRow Convert2WASTLAGE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWASTLAGE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WASLMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WASLKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WASLWERK"] = " ".PadRight(3 ); 
         dwReturn["WASLABT"] = " ".PadRight(3 ); 
         dwReturn["WASLWAKZ"] = " ".PadRight(1 ); 
         dwReturn["WASLART"] = " ".PadRight(20 ); 
         dwReturn["WASLPOS"] = " ".PadRight(0 ); 
         dwReturn["WASLLAGE"] = " ".PadRight(0 ); 
         dwReturn["WASLPOSTYP"] = " ".PadRight(1 ); 
         dwReturn["WASLPARTGL"] = " ".PadRight(0 ); 
         dwReturn["WASLPGLKZ"] = " ".PadRight(1 ); 
         dwReturn["WASLVAR"] = " ".PadRight(2 ); 
         dwReturn["WASLFARBE"] = " ".PadRight(10 ); 
         dwReturn["WASLDESS"] = " ".PadRight(10 ); 
         dwReturn["WASLCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["WASLBESCHICH"] = " ".PadRight(10 ); 
         dwReturn["WASLAUFM"] = " ".PadRight(2 ); 
         dwReturn["WASLVERP"] = " ".PadRight(3 ); 
         dwReturn["WASLMATKZ"] = " ".PadRight(1 ); 
         dwReturn["WASLMKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WASLMWERK"] = " ".PadRight(3 ); 
         dwReturn["WASLMABT"] = " ".PadRight(3 ); 
         dwReturn["WASLMART"] = " ".PadRight(20 ); 
         dwReturn["WASLMVAR"] = " ".PadRight(3 ); 
         dwReturn["WASLMKZFARBE"] = " ".PadRight(1 ); 
         dwReturn["WASLMFARBE"] = " ".PadRight(10 ); 
         dwReturn["WASLMDESS"] = " ".PadRight(10 ); 
         dwReturn["WASLMCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["WASLMBESCHICH"] = " ".PadRight(10 ); 
         dwReturn["WASLVERBR"] = " ".PadRight(0 ); 
         dwReturn["WASLVERBR100"] = " ".PadRight(0 ); 
         dwReturn["WASLMAEH"] = " ".PadRight(3 ); 
         dwReturn["WASLMAEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WASLMAEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WASLMEEH"] = " ".PadRight(3 ); 
         dwReturn["WASLMEEHGRP"] = " ".PadRight(1 ); 
         dwReturn["WASLMEEHFKT"] = " ".PadRight(12 ); 
         dwReturn["WASLVERL"] = " ".PadRight(0 ); 
         dwReturn["WASLLO"] = " ".PadRight(2 ); 
         dwReturn["WASLDKZ"] = " ".PadRight(1 ); 
         dwReturn["WASLABRKZ"] = " ".PadRight(1 ); 
         dwReturn["WASLAUFKZ"] = " ".PadRight(1 ); 
         dwReturn["WASLTEXTSL"] = " ".PadRight(3 ); 
         dwReturn["WASLFILLER"] = " ".PadRight(51 ); 
         dwReturn["WASLAENZL"] = " ".PadRight(0 ); 
         dwReturn["WASLAENB"] = " ".PadRight(8 ); 
         dwReturn["WASLAEND"] = " ".PadRight(0 ); 
         dwReturn["WASLNEUB"] = " ".PadRight(8 ); 
         dwReturn["WASLNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWASTLAGE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWASTLAGE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTLAGE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWASTLAGE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWASTLAGE(dwLocal, ITXDBVERSION);
            }
            UpdateWASTLAGE(dwLocal);
        }
        public void InsertWASTLAGE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WASTLAGE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWASTLAGE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WASTLAGE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WASTLAGE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WASTLAGE";
            Return = Result;
            return Return;
        }
        public void DeleteWASTLAGE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WASTLAGE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWASTLAGE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WASTLAGE SET "
                    +"WASLMANDANT= :WASLMANDANT,"
                    +"WASLKUNDNR= :WASLKUNDNR,"
                    +"WASLWERK= :WASLWERK,"
                    +"WASLABT= :WASLABT,"
                    +"WASLWAKZ= :WASLWAKZ,"
                    +"WASLART= :WASLART,"
                    +"WASLPOS= :WASLPOS,"
                    +"WASLLAGE= :WASLLAGE,"
                    +"WASLPOSTYP= :WASLPOSTYP,"
                    +"WASLPARTGL= :WASLPARTGL,"
                    +"WASLPGLKZ= :WASLPGLKZ,"
                    +"WASLVAR= :WASLVAR,"
                    +"WASLFARBE= :WASLFARBE,"
                    +"WASLDESS= :WASLDESS,"
                    +"WASLCOLORIT= :WASLCOLORIT,"
                    +"WASLBESCHICH= :WASLBESCHICH,"
                    +"WASLAUFM= :WASLAUFM,"
                    +"WASLVERP= :WASLVERP,"
                    +"WASLMATKZ= :WASLMATKZ,"
                    +"WASLMKUNDNR= :WASLMKUNDNR,"
                    +"WASLMWERK= :WASLMWERK,"
                    +"WASLMABT= :WASLMABT,"
                    +"WASLMART= :WASLMART,"
                    +"WASLMVAR= :WASLMVAR,"
                    +"WASLMKZFARBE= :WASLMKZFARBE,"
                    +"WASLMFARBE= :WASLMFARBE,"
                    +"WASLMDESS= :WASLMDESS,"
                    +"WASLMCOLORIT= :WASLMCOLORIT,"
                    +"WASLMBESCHICH= :WASLMBESCHICH,"
                    +"WASLVERBR= :WASLVERBR,"
                    +"WASLVERBR100= :WASLVERBR100,"
                    +"WASLMAEH= :WASLMAEH,"
                    +"WASLMAEHGRP= :WASLMAEHGRP,"
                    +"WASLMAEHFKT= :WASLMAEHFKT,"
                    +"WASLMEEH= :WASLMEEH,"
                    +"WASLMEEHGRP= :WASLMEEHGRP,"
                    +"WASLMEEHFKT= :WASLMEEHFKT,"
                    +"WASLVERL= :WASLVERL,"
                    +"WASLLO= :WASLLO,"
                    +"WASLDKZ= :WASLDKZ,"
                    +"WASLABRKZ= :WASLABRKZ,"
                    +"WASLAUFKZ= :WASLAUFKZ,"
                    +"WASLTEXTSL= :WASLTEXTSL,"
                    +"WASLFILLER= :WASLFILLER,"
                    +"WASLAENZL= :WASLAENZL,"
                    +"WASLAENB= :WASLAENB,"
                    +"WASLAEND= :WASLAEND,"
                    +"WASLNEUB= :WASLNEUB,"
                    +"WASLNEUD= :WASLNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WASLMANDANT", OracleType.NVarChar).Value = dwData["WASLMANDANT"].ToString(); 
          or1.Parameters.Add("WASLKUNDNR", OracleType.NVarChar).Value = dwData["WASLKUNDNR"].ToString(); 
          or1.Parameters.Add("WASLWERK", OracleType.NVarChar).Value = dwData["WASLWERK"].ToString(); 
          or1.Parameters.Add("WASLABT", OracleType.NVarChar).Value = dwData["WASLABT"].ToString(); 
          or1.Parameters.Add("WASLWAKZ", OracleType.NVarChar).Value = dwData["WASLWAKZ"].ToString(); 
          or1.Parameters.Add("WASLART", OracleType.NVarChar).Value = dwData["WASLART"].ToString(); 
          or1.Parameters.Add("WASLPOS", OracleType.NVarChar).Value = dwData["WASLPOS"].ToString(); 
          or1.Parameters.Add("WASLLAGE", OracleType.NVarChar).Value = dwData["WASLLAGE"].ToString(); 
          or1.Parameters.Add("WASLPOSTYP", OracleType.NVarChar).Value = dwData["WASLPOSTYP"].ToString(); 
          or1.Parameters.Add("WASLPARTGL", OracleType.NVarChar).Value = dwData["WASLPARTGL"].ToString(); 
          or1.Parameters.Add("WASLPGLKZ", OracleType.NVarChar).Value = dwData["WASLPGLKZ"].ToString(); 
          or1.Parameters.Add("WASLVAR", OracleType.NVarChar).Value = dwData["WASLVAR"].ToString(); 
          or1.Parameters.Add("WASLFARBE", OracleType.NVarChar).Value = dwData["WASLFARBE"].ToString(); 
          or1.Parameters.Add("WASLDESS", OracleType.NVarChar).Value = dwData["WASLDESS"].ToString(); 
          or1.Parameters.Add("WASLCOLORIT", OracleType.NVarChar).Value = dwData["WASLCOLORIT"].ToString(); 
          or1.Parameters.Add("WASLBESCHICH", OracleType.NVarChar).Value = dwData["WASLBESCHICH"].ToString(); 
          or1.Parameters.Add("WASLAUFM", OracleType.NVarChar).Value = dwData["WASLAUFM"].ToString(); 
          or1.Parameters.Add("WASLVERP", OracleType.NVarChar).Value = dwData["WASLVERP"].ToString(); 
          or1.Parameters.Add("WASLMATKZ", OracleType.NVarChar).Value = dwData["WASLMATKZ"].ToString(); 
          or1.Parameters.Add("WASLMKUNDNR", OracleType.NVarChar).Value = dwData["WASLMKUNDNR"].ToString(); 
          or1.Parameters.Add("WASLMWERK", OracleType.NVarChar).Value = dwData["WASLMWERK"].ToString(); 
          or1.Parameters.Add("WASLMABT", OracleType.NVarChar).Value = dwData["WASLMABT"].ToString(); 
          or1.Parameters.Add("WASLMART", OracleType.NVarChar).Value = dwData["WASLMART"].ToString(); 
          or1.Parameters.Add("WASLMVAR", OracleType.NVarChar).Value = dwData["WASLMVAR"].ToString(); 
          or1.Parameters.Add("WASLMKZFARBE", OracleType.NVarChar).Value = dwData["WASLMKZFARBE"].ToString(); 
          or1.Parameters.Add("WASLMFARBE", OracleType.NVarChar).Value = dwData["WASLMFARBE"].ToString(); 
          or1.Parameters.Add("WASLMDESS", OracleType.NVarChar).Value = dwData["WASLMDESS"].ToString(); 
          or1.Parameters.Add("WASLMCOLORIT", OracleType.NVarChar).Value = dwData["WASLMCOLORIT"].ToString(); 
          or1.Parameters.Add("WASLMBESCHICH", OracleType.NVarChar).Value = dwData["WASLMBESCHICH"].ToString(); 
          or1.Parameters.Add("WASLVERBR", OracleType.NVarChar).Value = dwData["WASLVERBR"].ToString(); 
          or1.Parameters.Add("WASLVERBR100", OracleType.NVarChar).Value = dwData["WASLVERBR100"].ToString(); 
          or1.Parameters.Add("WASLMAEH", OracleType.NVarChar).Value = dwData["WASLMAEH"].ToString(); 
          or1.Parameters.Add("WASLMAEHGRP", OracleType.NVarChar).Value = dwData["WASLMAEHGRP"].ToString(); 
          or1.Parameters.Add("WASLMAEHFKT", OracleType.NVarChar).Value = dwData["WASLMAEHFKT"].ToString(); 
          or1.Parameters.Add("WASLMEEH", OracleType.NVarChar).Value = dwData["WASLMEEH"].ToString(); 
          or1.Parameters.Add("WASLMEEHGRP", OracleType.NVarChar).Value = dwData["WASLMEEHGRP"].ToString(); 
          or1.Parameters.Add("WASLMEEHFKT", OracleType.NVarChar).Value = dwData["WASLMEEHFKT"].ToString(); 
          or1.Parameters.Add("WASLVERL", OracleType.NVarChar).Value = dwData["WASLVERL"].ToString(); 
          or1.Parameters.Add("WASLLO", OracleType.NVarChar).Value = dwData["WASLLO"].ToString(); 
          or1.Parameters.Add("WASLDKZ", OracleType.NVarChar).Value = dwData["WASLDKZ"].ToString(); 
          or1.Parameters.Add("WASLABRKZ", OracleType.NVarChar).Value = dwData["WASLABRKZ"].ToString(); 
          or1.Parameters.Add("WASLAUFKZ", OracleType.NVarChar).Value = dwData["WASLAUFKZ"].ToString(); 
          or1.Parameters.Add("WASLTEXTSL", OracleType.NVarChar).Value = dwData["WASLTEXTSL"].ToString(); 
          or1.Parameters.Add("WASLFILLER", OracleType.NVarChar).Value = dwData["WASLFILLER"].ToString(); 
          or1.Parameters.Add("WASLAENZL", OracleType.NVarChar).Value = dwData["WASLAENZL"].ToString(); 
          or1.Parameters.Add("WASLAENB", OracleType.NVarChar).Value = dwData["WASLAENB"].ToString(); 
          or1.Parameters.Add("WASLAEND", OracleType.NVarChar).Value = dwData["WASLAEND"].ToString(); 
          or1.Parameters.Add("WASLNEUB", OracleType.NVarChar).Value = dwData["WASLNEUB"].ToString(); 
          or1.Parameters.Add("WASLNEUD", OracleType.NVarChar).Value = dwData["WASLNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
